home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01a.txt
/
000070_icon-group-sender _Tue Jun 27 16:55:20 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA21064
for icon-group-addresses; Tue, 27 Jun 2000 16:55:06 -0700 (MST)
Message-Id: <200006272355.QAA21064@baskerville.CS.Arizona.EDU>
Date: Tue, 27 Jun 2000 13:08:59 -0700 (MST)
From: Gregg Townsend <gmt@baskerville.CS.Arizona.EDU>
To: Steve_Graham@labcorp.com, icon-group@optima.CS.Arizona.EDU
Subject: Re: Permutations/Combinations
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Content-Length: 1054
From: "Steve Graham" <Steve_Graham@labcorp.com>
Although I do not know how to utilize Icon's built-in features to generate
all possible combinations/permutations (which one is it?) where the letters
appear once and only once, I do believe that, given the generated list, I
will recognize the valid words. And I'm sure that Icon can EASILY produce
the list, whether the algorthim utilizes reversible assignment or not.
Can someone show me how?
The Icon program library contains a nice little permutation generator
(in the procs/strings.icn file):
procedure permute(s)
local i
if *s = 0 then return ""
suspend s[i := 1 to *s] || permute(s[1:i] || s[i+1:0])
end
So to generate all 720 permutations you'd just do this:
procedure main()
every write(permute("abelmr"))
end
---------------------------------------------------------------------------
Gregg Townsend Staff Scientist The University of Arizona
gmt@cs.arizona.edu Computer Science Tucson, Arizona, USA